home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-11 / rlib.zip / RL_NAMES.PRG < prev    next >
Text File  |  1993-01-04  |  2KB  |  66 lines

  1. * Function: NAMESPLIT
  2. * Author..: Richard Low
  3. * Syntax..: NAMESPLIT( <expC> )
  4. * Returns.: 'Low, Richard C.' where p_name was 'Richard C. Low'
  5. *            only if p_name contains at least one space, otherwise
  6. *            p_name itself is returned.
  7. * Usage...: Useful in converting names listed as Firstname first etc..
  8. *           into Lastname first format.  Also useful for locating names
  9. *           which were indexed on:
  10. *
  11. *               SUBSTR( TRIM(Lastname) + ', ' + TRIM(Firstname) ;
  12. *               + ' ' + Middlename + SPACE(32) , 1, 32)
  13. *
  14. * Note....: The above index expression is built to, then limited to 32
  15. *           characters in order to keep the index key a constant length
  16.  
  17. FUNCTION NAMESPLIT
  18. PARAMETER p_name
  19. PRIVATE f_first, f_middle, f_last, f_midstart, f_laststart
  20.  
  21. *-- first get rid of excess blanks
  22. p_name = TRIM(p_name)
  23.  
  24. *-- set up some working space
  25. STORE '' TO f_first, f_middle, f_last
  26.  
  27. *-- test if name is alpha and a space can be found in it
  28. *-- if so, there must be more than one word entered (2 names)
  29. *-- either first and last, or first, middle and last
  30. IF ISALPHA(p_name) .AND. ' ' $ p_name
  31.  
  32.    *-- any middle name will start at the space, plus one
  33.    f_midstart = AT(' ',p_name) + 1
  34.  
  35.    *-- and the last name should start at the space after the first
  36.    f_laststart = AT(' ', SUBSTR(p_name, f_midstart) ) + 1
  37.  
  38.    *-- start of last name will be 1 if the AT() returned 0, not found
  39.    IF f_laststart = 1
  40.       *-- must be only 2 words in string, First and Last name
  41.       f_first = TRIM(SUBSTR(p_name, 1, (f_midstart - 1)))
  42.       f_last  = TRIM(SUBSTR(p_name, f_midstart))
  43.  
  44.    ELSE
  45.       *-- otherwise, must be more than 2 names entered: First Middle Last
  46.       f_first  = TRIM(SUBSTR(p_name, 1, (f_midstart - 1)))
  47.       f_middle = TRIM(SUBSTR(p_name, f_midstart, (f_laststart - 1)))
  48.       f_last   = TRIM(SUBSTR(p_name, f_laststart + f_midstart - 1))
  49.  
  50.       *-- if the last name is a Title
  51.       IF UPPER(TRIM(f_last)) $ ',JR. ,SR. ,III ,II ,2ND ,3RD ,4TH  M.D. PHD'
  52.          *-- its not really the last name, middle is, so tack it on to end
  53.          f_last = TRIM(f_middle) + ' ' + TRIM(f_last)
  54.  
  55.          *-- scratch the middle name part
  56.          f_middle = ''
  57.       ENDIF
  58.    ENDIF
  59.  
  60.    *-- now construct the end result in form LASTNAME, FIRSTNAME MIDDLE
  61.    p_name = TRIM( f_last + ', ' + f_first + ' ' + f_middle )
  62. ENDIF
  63.  
  64. *-- give it back
  65. RETURN p_name
  66.